from flask import Blueprint, jsonify
from flask_restful import Resource, Api
from models.model import *
teacher_bp = Blueprint('teacher_bp', __name__, url_prefix='/')
api = Api(teacher_bp)

class Teacher_all(Resource):
    def get(self):
        teacher_info = Teacher.query.limit(10).all()
        teacher_list = []
        print(teacher_info)
        for teacher in teacher_info:
            a = {
                'id':teacher.id,
                'name':teacher.name,
                'attention_num':teacher.attention_num,
                'info':teacher.info,
                'status':teacher.status,
                'photo':teacher.photo
            }
            teacher_list.append(a)
        return jsonify({
            'code':200,
            'teacher_list':teacher_list
        })

class Teacher_one(Resource):
    def get(self, id):
        teacher_one = Teacher.query.filter(Teacher.id == id).one()
        teacher_one_list = {
            'id': teacher_one.id,
            'name': teacher_one.name,
            'attention_num': teacher_one.attention_num,
            'info': teacher_one.info,
            'status': teacher_one.status,
            'photo': teacher_one.photo
        }
        return jsonify({
            'code':200,
            'teacher_one_list':teacher_one_list
        })




api.add_resource(Teacher_all, 'get_teacher')
api.add_resource(Teacher_one, 'get_teacher/<int:id>')